// 筛选需要的表单配置项
export const findConfigIndex = (formArr,modelName) => {
  let index = formArr.findIndex((value) => {
    return value.modelName === modelName
  })
  return index !== -1 ? index : ''
}

/**
 * 下载文件
 *
 * @params base     文件base64 字符串
 * @parmas fileName 下载的文件名称
 */
export const exportSearchList = (base, fileName) => {
  var blob = b64toBlob(base, 'application/vnd.ms-excel;charset=utf-8')
  let url = window.URL.createObjectURL(blob)
  let downLoad = document.createElement('a')
  downLoad.style.display = 'none'
  downLoad.href = url
  downLoad.setAttribute('download', fileName+'.xlsx')
  document.body.appendChild(downLoad)
  downLoad.click()
  document.body.removeChild(downLoad)
  window.URL.revokeObjectURL(url)
}

// base64 转 blob 对象
function b64toBlob (b64Data, contentType, sliceSize) {
  contentType = contentType || ''
  sliceSize = sliceSize || 512
  var byteCharacters = window.atob(b64Data)
  var byteArrays = []
  for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
    var slice = byteCharacters.slice(offset, offset + sliceSize)
    var byteNumbers = new Array(slice.length)
    for (var i = 0; i < slice.length; i++) {
      byteNumbers[i] = slice.charCodeAt(i)
    }
    var byteArray = new Uint8Array(byteNumbers)
    byteArrays.push(byteArray)
  }
  var blob = new Blob(byteArrays, { type: contentType })
  return blob
}